package com.oocl.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;

public class DBUtil {
	private static BasicDataSource ds;
	private static String driver = "oracle.jdbc.OracleDriver";
	private static String url = "jdbc:oracle:thin:@localhost:1522:orcl";
	private static String userName = "garen";
	private static String password = "123";

	static {
		ds = new BasicDataSource();
		ds.setUrl(url);
		ds.setDriverClassName(driver);
		ds.setUsername(userName);
		ds.setPassword(password);
	}

	public static Connection createConnection() {
		Connection con = null;
		try {
			con = ds.getConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return con;
	}

	public static void close(Connection con, PreparedStatement stat,
			ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();

			}
			if (stat != null) {
				stat.close();
			}
			if (con != null) {
				con.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
